﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using Telerik.Web.UI;
using SubSonic.Sugar;
using System.Security;
using MediaMonitor.Common;
using Ionic.Zip;
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System.Drawing;
using OfficeOpenXml.Drawing.Chart;
using System.Drawing;


using Telerik.Charting;
using Telerik.Charting.Styles;
using System.Transactions;
using System.Web.UI.HtmlControls;
using SubSonic;
using System.Configuration;
using System.Collections;


namespace MediaMonitor.Users
{
    public partial class Report_NewAlertAfterFilter : Adex.BasePage
    {

        string mediaTypeName = "";
        string sDate = "";
        string eDate = "";
        string AdvertiserMake = "";
        string AdvertiserName = "";
        string NewsTitle = "";
        string Calification = "";
        bool TitleNews = false;
        bool Summary = false;
        bool Text = false;
        string mediaCode = "";
        int pagesize = 12;
        string mediaTypeNameMake = "";
        string ddlValue = "";
        string TV = "";
        string Radio = "";
        string Internet = "";
        string Press = "";
        string InMedia = "";
        string Code = "";
        string days = "";
        string Importancia = string.Empty;
        protected void Page_Init(object sender, EventArgs e)
        {

        }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.Cookies["User"]["CompanyCode"] == null || Request.Cookies["NoSummary"] == null)
                Response.Redirect("../logout.aspx");
            else
            {
                DataTable dt = SPs.Getlogoname(Convert.ToInt32(Request.Cookies["User"]["CompanyCode"])).GetDataSet().Tables[0];
                //imgLogo.Src = "../get-thumb.aspx?f=images/companies/tn/" + dt.Rows[0]["Logo"].ToString() + "&w=70";
            }
            if (!IsPostBack)
            {
                if (Request.Cookies["NoSummary"].Value.ToString() == "True")
                {
                    FillReport();
                    Inngrid();
                    //objDS.SelectParameters["MediaTypeCode"].DefaultValue = MediaType.ToString();
                    //objDSExport.SelectParameters["MediaTypeCode"].DefaultValue = MediaType.ToString();
                    //Session["mtc"] = Convert.ToInt32(MediaType.ToString());

                    radGrid.DataSourceID = "objDS";

                    //PrepareGridColumns();
                    radGridAll.Visible = false;
                    ChartAvenueReport.Visible = false;
                    SummaryDIVTOP.Visible = false;
                    SummaryDIVTOP.Style.Add("display", "none");
                    InnerDIV.Style.Add("display", "block");
                    InnerDIV.Visible = true;
                    InnerDIVTOP.Visible = true;
                    BindChartResult(ViewState["mediaTypeName"].ToString(), ViewState["Calification"].ToString());

                }
                else
                {
                    SummaryDIVTOP.Style.Add("display", "block");
                }
            }
          
            bindgrid();
        }

        public void FillReport()
        {
            sDate = Utility.GetRequestedVal("sd", "01_01_2000").Replace("_", "/") + " 00:00:00.000";
            ViewState["sDate"] = sDate;
           
            eDate = Utility.GetRequestedVal("ed", "01_01_2000").Replace("_", "/") + " 23:59:59.999";
            ViewState["eDate"] = eDate;
           
            mediaTypeName = Utility.GetRequestedVal("NewsType", "");
            ViewState["mediaTypeName"] = mediaTypeName;
           
            AdvertiserMake = Utility.GetRequestedVal("AdvertiserMake", "");
            ViewState["AdvertiserMake"] = AdvertiserMake;
           
            AdvertiserName = Utility.GetRequestedVal("Advertiser", "");
            ViewState["AdvertiserName"] = AdvertiserName;
            Importancia = Utility.GetRequestedVal("Importancia", "");
            ViewState["Importancia"] = Importancia;
            NewsTitle = Utility.GetRequestedVal("title", "");
            ViewState["NewsTitle"] = NewsTitle;
           
            if (NewsTitle != "")
                Session["NewsTitle"] = NewsTitle;
           
            Calification = Utility.GetRequestedVal("Calification", "");
            ViewState["Calification"] = Calification;

            TitleNews = Convert.ToBoolean(Utility.GetRequestedVal("TitleNews", ""));
            ViewState["TitleNews"] = TitleNews;
           
            Summary = Convert.ToBoolean(Utility.GetRequestedVal("Summary", ""));
            ViewState["Summary"] = Summary;
            
            Text = Convert.ToBoolean(Utility.GetRequestedVal("Text", ""));
            ViewState["Text"] = Text;
            
            mediaCode = Utility.GetRequestedVal("mediaCode", "");
            ViewState["mediaCode"] = mediaCode;
           
            mediaTypeNameMake = Utility.GetRequestedVal("mediaTypeNameMake", "");
            ViewState["mediaTypeNameMake"] = mediaTypeNameMake;
            
            TV = Utility.GetRequestedVal("TV", "");
            Radio = Utility.GetRequestedVal("Radio", "");
            Press = Utility.GetRequestedVal("Press", "");
            Internet = Utility.GetRequestedVal("Internet", "");
            Code = Utility.GetRequestedVal("Code", "");
            days = Utility.GetRequestedVal("days", "");
            ViewState["days"] = days;
        }
       
       
        protected void objDSAll_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (!e.ExecutingSelectCount)
            {
                e.Arguments.MaximumRows = radGridAll.PageSize;
                e.InputParameters.Add("e", e);
            }
        }
       
        	public void BindChart()
		{
			bool flag;
			Color[] green = new Color[] { Color.Green, Color.Red, Color.Blue };
			Color[] barColors = green;
			ReportFuncs rpt = new ReportFuncs();
            DataTable dt = rpt.GetReportAll_NewsAlertChartAfterFilter(this.ViewState["sDate"].ToString(), this.ViewState["eDate"].ToString(), this.ViewState["mediaTypeName"].ToString(), this.ViewState["AdvertiserName"].ToString(), this.ViewState["NewsTitle"].ToString(), this.ViewState["Calification"].ToString(), Convert.ToBoolean(this.ViewState["TitleNews"].ToString()), Convert.ToBoolean(this.ViewState["Summary"].ToString()), Convert.ToBoolean(this.ViewState["Text"].ToString()), "", this.ViewState["AdvertiserMake"].ToString(), "", ViewState["mediaTypeNameMake"].ToString(), ViewState["days"].ToString(), Convert.ToInt32(Request.Cookies["User"]["UserID"]), ViewState["Importancia"].ToString());
			this.ViewState["dvSummaryNewsAlertChart"] = dt;
			this.ChartAvenueReport.DataSource = dt;
			this.ChartAvenueReport.DataBind();
			flag = (!(dt.Rows[0][1].ToString() == "0") || !(dt.Rows[1][1].ToString() == "0") ? true : !(dt.Rows[2][1].ToString() == "0"));
			bool flag1 = flag;
			if (!flag1)
			{
				this.ChartAvenueReport.Visible = false;
			}
			this.ChartAvenueReport.PlotArea.XAxis.AxisLabel.Visible = false;
			int i = 0;
			this.ChartAvenueReport.PlotArea.XAxis.AutoScale = false;
			this.ChartAvenueReport.PlotArea.XAxis.AddRange(1, 3, 1);
			IEnumerator<ChartSeriesItem> enumerator = this.ChartAvenueReport.Series[0].Items.GetEnumerator();
			try
			{
				while (true)
				{
					flag1 = enumerator.MoveNext();
					if (!flag1)
					{
						break;
					}
					ChartSeriesItem item = enumerator.Current;
					int num = i;
					i = num + 1;
					item.Appearance.FillStyle.MainColor = barColors[num];
				}
			}
			finally
			{
				flag1 = enumerator == null;
				if (!flag1)
				{
					enumerator.Dispose();
				}
			}
			this.ChartAvenueReport.PlotArea.XAxis[0].TextBlock.Text = dt.Rows[0][1].ToString();
			this.ChartAvenueReport.PlotArea.XAxis[1].TextBlock.Text = dt.Rows[1][1].ToString();
			this.ChartAvenueReport.PlotArea.XAxis[2].TextBlock.Text = dt.Rows[2][1].ToString();
			this.ChartAvenueReport.Skin = "LightGreen";
		}

		public void BindChartResult(string MediaName, string Calification)
		{
			bool flag;
			Color[] green = new Color[] { Color.Green, Color.Red, Color.Blue };
			Color[] barColors = green;
			ReportFuncs rpt = new ReportFuncs();
            DataTable dt = rpt.GetReportAll_NewsAlertChartAfterFilter(this.ViewState["sDate"].ToString(), this.ViewState["eDate"].ToString(), this.ViewState["mediaTypeName"].ToString(), this.ViewState["AdvertiserName"].ToString(), this.ViewState["NewsTitle"].ToString(), this.ViewState["Calification"].ToString(), Convert.ToBoolean(this.ViewState["TitleNews"].ToString()), Convert.ToBoolean(this.ViewState["Summary"].ToString()), Convert.ToBoolean(this.ViewState["Text"].ToString()), "", this.ViewState["AdvertiserMake"].ToString(), "", ViewState["mediaTypeNameMake"].ToString(), ViewState["days"].ToString(), Convert.ToInt32(Request.Cookies["User"]["UserID"]), ViewState["Importancia"].ToString());
			this.ViewState["dvSummaryBindChartResult"] = dt;
			this.RadChartResult.DataSource = dt;
			this.RadChartResult.DataBind();
			flag = (!(dt.Rows[0][1].ToString() == "0") || !(dt.Rows[1][1].ToString() == "0") ? true : !(dt.Rows[2][1].ToString() == "0"));
			bool flag1 = flag;
			if (!flag1)
			{
				this.RadChartResult.Visible = false;
			}
			this.RadChartResult.PlotArea.XAxis.AxisLabel.Visible = false;
			int i = 0;
			this.RadChartResult.PlotArea.XAxis.AutoScale = false;
			this.RadChartResult.PlotArea.XAxis.AddRange(1, 3, 1);
			IEnumerator<ChartSeriesItem> enumerator = this.RadChartResult.Series[0].Items.GetEnumerator();
			try
			{
				while (true)
				{
					flag1 = enumerator.MoveNext();
					if (!flag1)
					{
						break;
					}
					ChartSeriesItem item = enumerator.Current;
					int num = i;
					i = num + 1;
					item.Appearance.FillStyle.MainColor = barColors[num];
				}
			}
			finally
			{
				flag1 = enumerator == null;
				if (!flag1)
				{
					enumerator.Dispose();
				}
			}
			this.RadChartResult.PlotArea.XAxis[0].TextBlock.Text = dt.Rows[0][1].ToString();
			this.RadChartResult.PlotArea.XAxis[1].TextBlock.Text = dt.Rows[1][1].ToString();
			this.RadChartResult.PlotArea.XAxis[2].TextBlock.Text = dt.Rows[2][1].ToString();
			this.RadChartResult.ChartTitle.TextBlock.Appearance.TextProperties.Font = new Font("Arial", 10f);
			this.RadChartResult.Legend.TextBlock.Appearance.TextProperties.Font = new Font("Arial", 7f);
			this.RadChartResult.Skin = "LightGreen";
		}

		public void bindgrid()
		{
			this.FillReport();
			this.BindChart();
			this.objDSAll.SelectParameters["mediaTypeName1"].DefaultValue = this.ViewState["mediaTypeName"].ToString();
			this.objDSAll.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
			this.objDSAll.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
			this.objDSAll.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
			this.objDSAll.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
			this.objDSAll.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
			this.objDSAll.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
			this.objDSAll.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
			this.objDSAll.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
			this.objDSAll.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
            this.objDSAll.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
            this.objDSAll.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
			this.objDSAll.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
            this.objDSAll.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
			this.radGridAll.DataSourceID = "objDSAll";
			this.SummaryDIVTOP.Visible = true;
			DataView dvSummaryCount = new DataView();
			dvSummaryCount = (DataView)this.objDSAll.Select();
			DataTable dtCount = new DataTable();
			dtCount = dvSummaryCount.ToTable();
			this.ViewState["dvSummaryNewsAlertCount"] = dtCount;
		}



        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        ///        Required method for Designer support - do not modify
        ///        the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ChartAvenueReport.Click += new Telerik.Web.UI.RadChart.ChartClickEventHandler(this.RadChart1_Click);
            this.RadChartResult.Click += new Telerik.Web.UI.RadChart.ChartClickEventHandler(this.RadChart1_Click);
        }
        #endregion

       
        string target = "";
        public  string PDFLink(string pdfname)
        {
            string filename = pdfname.Replace("/", "_").Replace(" ", "") + ".pdf";
            string path = Utility.AppPath+"/File_People_link/" + filename;
            System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("~/File_People_link/" + filename));
            if (file.Exists)
            {
                target = "_blank";
                return path;
            }
            else
            {
                target = "";
                return "#";
            }
        }
        public string GetTarget()
        {
            return target;
        }
        public void lstBrandsAndPeople_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            // in assumption that your data item's unique identifier type is Int32


            switch (e.CommandName)
            {

                case "pdfDownload":

                    string filename = e.CommandArgument.ToString().Replace("/","_").Replace(" ","") + ".pdf";
                    string path = Server.MapPath("~/File_People_link/" + filename);
                    System.IO.FileInfo file = new System.IO.FileInfo(path);
                    if (file.Exists)
                    {
                        Response.Redirect(Utility.AppPath + "/File_People_link/" + file.Name);
                        //Response.Clear();
                        //Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                        //Response.AddHeader("Content-Length", file.Length.ToString());
                        //Response.ContentType = "application/octet-stream";
                        //Response.WriteFile(file.FullName);
                        //Response.End();

                    }
                    else
                    {
                        AjaxFuncs.MsgBox(this, "File doesn't exist");
                    }

                    break;
            }
        }


     

        protected void ObjDS_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (!e.ExecutingSelectCount)
            {
                e.Arguments.MaximumRows = radGrid.PageSize;
                e.InputParameters.Add("e", e);
            }
        }
        protected void ObjDSread_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (!e.ExecutingSelectCount)
            {
                e.Arguments.MaximumRows = radGrid.PageSize;
                e.InputParameters.Add("e", e);
            }
        }
        protected void ObjDS_SelectingExport(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (!e.ExecutingSelectCount)
            {
                e.Arguments.MaximumRows = radGridAll.PageSize;
                e.InputParameters.Add("e", e);
            }
        }
        protected void ddlMediaType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string text = this.ddlMediaType.SelectedItem.Text;
            if (text != null)
            {
                if (text == "ALL")
                {
                    this.Inngrid();
                    this.radGrid.DataSourceID = "objDS";
                    this.radGridAll.Visible = false;
                    this.ChartAvenueReport.Visible = false;
                    this.SummaryDIVTOP.Visible = false;
                    this.InnerDIV.Style.Add("display", "block");
                    this.InnerDIV.Visible = true;
                    this.InnerDIVTOP.Visible = true;
                    this.BindChartResult(this.ViewState["mediaTypeName"].ToString(), this.ViewState["Calification"].ToString());
                    this.RadChartResult.Visible = true;
                }
                else
                {
                    if (text == "INTERNET")
                    {
                        this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Internet";
                        this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                        this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                        this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                        this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                        this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                        this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                        this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                        this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                        this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                        this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                        this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                        this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                        this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                        this.radGrid.DataSourceID = "objDS";
                        this.SummaryDIVTOP.Visible = true;
                        this.radGridAll.Visible = false;
                        this.ChartAvenueReport.Visible = false;
                        this.SummaryDIVTOP.Visible = false;
                        this.InnerDIV.Style.Add("display", "block");
                        this.InnerDIV.Visible = true;
                        this.InnerDIVTOP.Visible = true;
                        DataView dvSummary = new DataView();
                        dvSummary = (DataView)this.objDSAll.Select();
                        DataTable dtSummary = new DataTable();
                        dtSummary = dvSummary.ToTable();
                        this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                        this.BindChartResult("Internet", this.ViewState["Calification"].ToString());
                        this.RadChartResult.Visible = true;
                    }
                    else
                    {
                        if (text == "RADIO")
                        {
                            this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Radio";
                            this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                            this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                            this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                            this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                            this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                            this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                            this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                            this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                            this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                            this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                            this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                            this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                            this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                            this.radGrid.DataSourceID = "objDS";
                            this.SummaryDIVTOP.Visible = true;
                            this.radGridAll.Visible = false;
                            this.ChartAvenueReport.Visible = false;
                            this.SummaryDIVTOP.Visible = false;
                            this.InnerDIV.Style.Add("display", "block");
                            this.InnerDIV.Visible = true;
                            this.InnerDIVTOP.Visible = true;
                            DataView dvSummary1 = new DataView();
                            dvSummary1 = (DataView)this.objDSAll.Select();
                            DataTable dtSummary1 = new DataTable();
                            dtSummary1 = dvSummary1.ToTable();
                            this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary1;
                            this.BindChartResult("Radio", this.ViewState["Calification"].ToString());
                            this.RadChartResult.Visible = true;
                        }
                        else
                        {
                            if (text == "TV")
                            {
                                this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "TV";
                                this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                                this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                                this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                                this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                                this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                                this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                                this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                                this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                                this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                                this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                                this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                                this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                                this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                                this.radGrid.DataSourceID = "objDS";
                                this.SummaryDIVTOP.Visible = true;
                                this.radGridAll.Visible = false;
                                this.ChartAvenueReport.Visible = false;
                                this.SummaryDIVTOP.Visible = false;
                                this.InnerDIV.Style.Add("display", "block");
                                this.InnerDIV.Visible = true;
                                this.InnerDIVTOP.Visible = true;
                                DataView dvSummary2 = new DataView();
                                dvSummary2 = (DataView)this.objDSAll.Select();
                                DataTable dtSummary2 = new DataTable();
                                dtSummary2 = dvSummary2.ToTable();
                                this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary2;
                                this.BindChartResult("TV", this.ViewState["Calification"].ToString());
                                this.RadChartResult.Visible = true;
                            }
                            else
                            {
                                if (text == "PRESS")
                                {
                                    this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Press";
                                    this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                                    this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                                    this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                                    this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                                    this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                                    this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                                    this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                                    this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                                    this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                                    this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                                    this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                                    this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                                    this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                                    this.radGrid.DataSourceID = "objDS";
                                    this.SummaryDIVTOP.Visible = true;
                                    this.radGridAll.Visible = false;
                                    this.ChartAvenueReport.Visible = false;
                                    this.SummaryDIVTOP.Visible = false;
                                    this.InnerDIV.Style.Add("display", "block");
                                    this.InnerDIV.Visible = true;
                                    this.InnerDIVTOP.Visible = true;
                                    DataView dvSummary3 = new DataView();
                                    dvSummary3 = (DataView)this.objDSAll.Select();
                                    DataTable dtSummary3 = new DataTable();
                                    dtSummary3 = dvSummary3.ToTable();
                                    this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary3;
                                    this.BindChartResult("Press", this.ViewState["Calification"].ToString());
                                    this.RadChartResult.Visible = true;
                                }
                            }
                        }
                    }
                }
            }
        }

        protected void ddlSortNews_SelectedIndexChanged(object sender, EventArgs e)
        {
            string text = this.ddlSortNews.SelectedItem.Text;
            if (text != null)
            {
                if (text == "Media Type")
                {
                    this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "MediaType";
                    this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                    this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                    this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                    this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                    this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                    this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                    this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                    this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                    this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                    this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                    this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                    this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                    this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                    this.radGrid.DataSourceID = "objDS";
                    this.SummaryDIVTOP.Visible = true;
                    this.radGridAll.Visible = false;
                    this.ChartAvenueReport.Visible = false;
                    this.SummaryDIVTOP.Visible = false;
                    this.InnerDIV.Style.Add("display", "block");
                    this.InnerDIV.Visible = true;
                    this.InnerDIVTOP.Visible = true;
                    DataView dvSummary3 = new DataView();
                    dvSummary3 = (DataView)this.objDSAll.Select();
                    DataTable dtSummary3 = new DataTable();
                    dtSummary3 = dvSummary3.ToTable();
                    this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary3;
                    this.BindChartResult("MediaType", this.ViewState["Calification"].ToString());
                    this.RadChartResult.Visible = true;
                }
                else
                {
                    if (text == "Title")
                    {
                        this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Title";
                        this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                        this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                        this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                        this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                        this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                        this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                        this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                        this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                        this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                        this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                        this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                        this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                        this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                        this.radGrid.DataSourceID = "objDS";
                        this.SummaryDIVTOP.Visible = true;
                        this.radGridAll.Visible = false;
                        this.ChartAvenueReport.Visible = false;
                        this.SummaryDIVTOP.Visible = false;
                        this.InnerDIV.Style.Add("display", "block");
                        this.InnerDIV.Visible = true;
                        this.InnerDIVTOP.Visible = true;
                        DataView dvSummary = new DataView();
                        dvSummary = (DataView)this.objDSAll.Select();
                        DataTable dtSummary = new DataTable();
                        dtSummary = dvSummary.ToTable();
                        this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                        this.BindChartResult("Title", this.ViewState["Calification"].ToString());
                        this.RadChartResult.Visible = true;
                    }
                    else
                    {
                        if (text == "Chronological")
                        {
                            this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Chronological";
                            this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                            this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                            this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                            this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                            this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                            this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                            this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                            this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                            this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                            this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                            this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                            this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                            this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                            this.radGrid.DataSourceID = "objDS";
                            this.SummaryDIVTOP.Visible = true;
                            this.radGridAll.Visible = false;
                            this.ChartAvenueReport.Visible = false;
                            this.SummaryDIVTOP.Visible = false;
                            this.InnerDIV.Style.Add("display", "block");
                            this.InnerDIV.Visible = true;
                            this.InnerDIVTOP.Visible = true;
                            DataView dvSummary1 = new DataView();
                            dvSummary1 = (DataView)this.objDSAll.Select();
                            DataTable dtSummary1 = new DataTable();
                            dtSummary1 = dvSummary1.ToTable();
                            this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary1;
                            this.BindChartResult("Chronological", this.ViewState["Calification"].ToString());
                            this.RadChartResult.Visible = true;
                        }
                        else
                        {
                            if (text == "Most Recent")
                            {
                                this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "MostRecent";
                                this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                                this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                                this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                                this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                                this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                                this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                                this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                                this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                                this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                                this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                                this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                                this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                                this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                                this.radGrid.DataSourceID = "objDS";
                                this.SummaryDIVTOP.Visible = true;
                                this.radGridAll.Visible = false;
                                this.ChartAvenueReport.Visible = false;
                                this.SummaryDIVTOP.Visible = false;
                                this.InnerDIV.Style.Add("display", "block");
                                this.InnerDIV.Visible = true;
                                this.InnerDIVTOP.Visible = true;
                                DataView dvSummary2 = new DataView();
                                dvSummary2 = (DataView)this.objDSAll.Select();
                                DataTable dtSummary2 = new DataTable();
                                dtSummary2 = dvSummary2.ToTable();
                                this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary2;
                                this.BindChartResult("MostRecent", this.ViewState["Calification"].ToString());
                                this.RadChartResult.Visible = true;
                            }
                        }
                    }
                }
            }
        }

        private void Inngrid()
        {
            objDS.SelectParameters["mediaTypeName1"].DefaultValue = ViewState["mediaTypeName"].ToString();
            objDS.SelectParameters["Date1"].DefaultValue = ViewState["sDate"].ToString();
            objDS.SelectParameters["Date2"].DefaultValue = ViewState["eDate"].ToString();
            objDS.SelectParameters["AdvertiserMake"].DefaultValue = ViewState["AdvertiserMake"].ToString();
            objDS.SelectParameters["AdvertiserName1"].DefaultValue = ViewState["AdvertiserName"].ToString(); ;
            objDS.SelectParameters["NewsTitle1"].DefaultValue = ViewState["NewsTitle"].ToString();
            objDS.SelectParameters["Calification1"].DefaultValue = ViewState["Calification"].ToString();
            objDS.SelectParameters["TitleNews"].DefaultValue = ViewState["TitleNews"].ToString();
            objDS.SelectParameters["Summary"].DefaultValue = ViewState["Summary"].ToString();
            objDS.SelectParameters["Text"].DefaultValue = ViewState["Text"].ToString();
            objDSAll.SelectParameters["mediaCode"].DefaultValue = ViewState["mediaCode"].ToString();
            objDSAll.SelectParameters["days"].DefaultValue = ViewState["days"].ToString();
            this.objDSAll.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
            this.objDSAll.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
        }
        protected void lnlBack_Clicked(object sender, System.EventArgs e)
        {
            InnerDIV.Style.Add("display", "none");
            InnerDIVTOP.Visible = false;
            radGridAll.Visible = true;
            SummaryDIVTOP.Visible = true;
            ChartAvenueReport.Visible = true;

        }
        

        protected void btnExportSummary_Click(object sender, EventArgs e)
        {
            DataTable dtDetails = (DataTable)ViewState["dvSummaryNewsAlertDetail"];
            if (!dtDetails.Columns.Contains("Date"))
                dtDetails.Columns.Add("Date");
            if (dtDetails.Columns.Contains("RFDate"))
            {
                foreach (DataRow dr in dtDetails.Rows)
                {
                    string date = dr["RFDate"].ToString();
                    dr["Date"] = date.Substring(0, 10);
                    //dr["Date"] = String.Format("{0:dd.MM.yyyy}", dr["RFDate"]);
                }
            }
            if (dtDetails.Columns.Contains("ID"))
            {
                dtDetails.Columns.Remove("ID");
                dtDetails.Columns.Remove("MediaTypeName");
                dtDetails.Columns.Remove("MediaTypeCode");
                dtDetails.Columns.Remove("MediaCode");
                dtDetails.Columns.Remove("SectionCode");
                dtDetails.Columns.Remove("Totalrecord");
                dtDetails.Columns.Remove("SumColumn");
                dtDetails.Columns.Remove("RFDate");

            }

            DumpExcelSummary((DataTable)ViewState["dvSummaryNewsAlertCount"], (DataTable)ViewState["dvSummaryNewsAlertChart"], dtDetails);
        }
        private void DumpExcelSummary(DataTable tblCount, DataTable tblChart, DataTable tbldetails)
        {

            Int32 tblColumnCount = tblCount.Columns.Count;
            int row = tblChart.Rows.Count;
            if (tblColumnCount > 0)
            {
                using (ExcelPackage pck = new ExcelPackage())
                {
                    try
                    {
                        ExcelWorksheet ws = pck.Workbook.Worksheets.Add("MediaMonitor-News&Comments");
                        ws.Cells["A1"].LoadFromDataTable(tblCount, true);
                        ws.Cells["A25"].LoadFromDataTable(tblChart, true);
                        ws.Cells["A30"].LoadFromDataTable(tbldetails, true);
                        ws.DefaultColWidth = 20;
                        using (ExcelRange rngSummary = ws.Cells["A1:D1"])
                        {
                            rngSummary.Style.Font.Bold = true;
                        }
                        using (ExcelRange rngUserSelection = ws.Cells["A30:O30"])
                        {
                            rngUserSelection.Style.Font.Bold = true;
                        }
                        ws.Cells["A30:T30"].AutoFilter = true;
                        var BarChart = ws.Drawings.AddChart("Competition Chart", eChartType.ColumnClustered) as ExcelBarChart;
                        //Set top left corner to row 1 column 2
                        BarChart.SetPosition(3, 2, 2, 2);
                        BarChart.SetSize(800, 400);
                        BarChart.Title.Text = "News & comments calification";
                        BarChart.Style = eChartStyle.Style26;
                        BarChart.Legend.Remove();
                        BarChart.DataLabel.ShowValue = true;
                        BarChart.DataLabel.Font.Bold = true;
                        BarChart.DataLabel.Border.LineCap = OfficeOpenXml.Drawing.eLineCap.Round;
                        BarChart.Series.Add(ExcelRange.GetAddress(26, 2, 28, 2), ExcelRange.GetAddress(26, 1, 28, 1));
                    }
                    catch { }
                    Response.Clear();
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", "attachment;  filename=MediaMonitor-News&Comments.xlsx");
                    Response.BinaryWrite(pck.GetAsByteArray());
                    Response.End();
                }
            }
        }


        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataTable dtDetails = (DataTable)ViewState["dvSummaryNewsAlertDetail"];
            if (!dtDetails.Columns.Contains("Date"))
                dtDetails.Columns.Add("Date");
            if (dtDetails.Columns.Contains("RFDate"))
            {
                foreach (DataRow dr in dtDetails.Rows)
                {
                    string date = dr["RFDate"].ToString();
                    dr["Date"] = date.Substring(0, 10);
                    //dr["Date"] = String.Format("{0:dd.MM.yyyy}", dr["RFDate"]);
                }
            }
            if (dtDetails.Columns.Contains("ID"))
            {
                dtDetails.Columns.Remove("ID");
                dtDetails.Columns.Remove("MediaTypeName");
                dtDetails.Columns.Remove("MediaTypeCode");
                dtDetails.Columns.Remove("MediaCode");
                dtDetails.Columns.Remove("SectionCode");
                dtDetails.Columns.Remove("Totalrecord");
                dtDetails.Columns.Remove("SumColumn");
                dtDetails.Columns.Remove("RFDate");
            }
            //dtDetails.Columns.Remove("CountRecord");
            DataTable tblcount = (DataTable)ViewState["dvSummaryBindChartResult"];
            DumpSummary(dtDetails, tblcount);
        }
        private void DumpSummary(DataTable tbldetails, DataTable tblChart)
        {
            Int32 tblColumnCount = tbldetails.Columns.Count;
            int row = tbldetails.Rows.Count;
            if (tblColumnCount > 0)
            {
                using (ExcelPackage pck = new ExcelPackage())
                {
                    try
                    {
                        //Create the worksheet
                        ExcelWorksheet ws = pck.Workbook.Worksheets.Add("MediaMonitor-News&CommentsDetail");
                        ws.Cells["A25"].LoadFromDataTable(tblChart, true);
                        ws.Cells["A30"].LoadFromDataTable(tbldetails, true);
                        ws.DefaultColWidth = 20;
                        using (ExcelRange rngSummary = ws.Cells["A1:D1"])
                        {
                            rngSummary.Style.Font.Bold = true;
                        }
                        using (ExcelRange rngUserSelection = ws.Cells["A25:O25"])
                        {
                            rngUserSelection.Style.Font.Bold = true;
                        }
                        var BarChart = ws.Drawings.AddChart("Competition Chart", eChartType.ColumnClustered) as ExcelBarChart;
                        //Set top left corner to row 1 column 2
                        BarChart.SetPosition(3, 2, 2, 2);
                        BarChart.SetSize(800, 400);
                        BarChart.Title.Text = "News & comments calification";
                        BarChart.Style = eChartStyle.Style26;
                        BarChart.Legend.Remove();
                        BarChart.DataLabel.ShowValue = true;
                        BarChart.DataLabel.Font.Bold = true;
                        BarChart.DataLabel.Border.LineCap = OfficeOpenXml.Drawing.eLineCap.Round;
                        BarChart.Series.Add(ExcelRange.GetAddress(26, 2, 28, 2), ExcelRange.GetAddress(26, 1, 28, 1));
                    }
                    catch { }
                    Response.Clear();
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", "attachment;  filename=MediaMonitor-News&Comments.xlsx");
                    Response.BinaryWrite(pck.GetAsByteArray());
                    Response.End();
                }
            }
        }

        private void RadChart1_Click(object sender, ChartClickEventArgs args)
        {
            if (args.SeriesItem != null)
            {
                this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = this.ViewState["mediaTypeName"].ToString();
                this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                this.objDS.SelectParameters["Calification1"].DefaultValue = args.SeriesItem.Name;
                this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                DataView dvSummary = new DataView();
                dvSummary = (DataView)this.objDS.Select();
                DataTable dtSummary = new DataTable();
                dtSummary = dvSummary.ToTable();
                this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                this.radGrid.DataSourceID = "objDS";
                this.radGridAll.Visible = false;
                this.ChartAvenueReport.Visible = false;
                this.SummaryDIVTOP.Visible = false;
                this.InnerDIV.Style.Add("display", "block");
                this.InnerDIVTOP.Visible = true;
                this.BindChartResult(this.ViewState["mediaTypeName"].ToString(), args.SeriesItem.Name);
            }
            else
            {
                FillReport();
                Inngrid();
                //objDS.SelectParameters["MediaTypeCode"].DefaultValue = MediaType.ToString();
                //objDSExport.SelectParameters["MediaTypeCode"].DefaultValue = MediaType.ToString();
                //Session["mtc"] = Convert.ToInt32(MediaType.ToString());

                radGrid.DataSourceID = "objDS";

                //PrepareGridColumns();
                radGridAll.Visible = false;
                ChartAvenueReport.Visible = false;
                SummaryDIVTOP.Visible = false;
                SummaryDIVTOP.Style.Add("display", "none");
                InnerDIV.Style.Add("display", "block");
                InnerDIV.Visible = true;
                InnerDIVTOP.Visible = true;
                BindChartResult(ViewState["mediaTypeName"].ToString(), ViewState["Calification"].ToString());
            }
        }

        protected void radGrid_ItemCommand(object source, GridCommandEventArgs e)
        {
            GridDataItem radItem;
            Label lbl;
            Exception ex2;
            string ID;
            IEnumerator enumerator;
            IDisposable disposable;
            GridDataItem item = (GridDataItem)e.Item;
            RadGrid gridComment = (RadGrid)item.FindControl("radGridComment");
            bool commandName = !(e.CommandName == "Comment");
            if (!commandName)
            {
                enumerator = this.radGrid.Items.GetEnumerator();
                try
                {
                    while (true)
                    {
                        commandName = enumerator.MoveNext();
                        if (!commandName)
                        {
                            break;
                        }
                        radItem = (GridDataItem)enumerator.Current;
                        ((LinkButton)radItem.FindControl("LnkComment")).Visible = true;
                        ((HtmlGenericControl)radItem.FindControl("CommemtDIV")).Visible = false;
                    }
                }
                finally
                {
                    disposable = enumerator as IDisposable;
                    commandName = disposable == null;
                    if (!commandName)
                    {
                        disposable.Dispose();
                    }
                }
                lbl = (Label)item.FindControl("lblNews");
                ((HtmlGenericControl)item.FindControl("CommemtDIV")).Visible = true;
                gridComment.DataSourceID = "objDSExport";
                this.objDSExport.SelectParameters["NewsID"].DefaultValue = lbl.Text;
                ((LinkButton)item.FindControl("LnkComment")).Visible = false;
            }
            commandName = !(e.CommandName == "ReadMore");
            if (commandName)
            {
                commandName = !(e.CommandName == "Save");
                if (!commandName)
                {
                    commandName = this.Request.Cookies["User"]["UserID"] != null;
                    if (!commandName)
                    {
                        base.Response.Redirect("../login.aspx");
                    }
                    lbl = (Label)item.FindControl("lblNews");
                    TextBox txt = (TextBox)item.FindControl("txtComment");
                    TransactionOptions options = new TransactionOptions();
                    options.Timeout = new TimeSpan(0, 2, 0);
                    options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                    TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, options);
                    try
                    {
                        SharedDbConnectionScope conn = new SharedDbConnectionScope(ConfigurationManager.ConnectionStrings["DBAdex"].ToString());
                        try
                        {
                            try
                            {
                                commandName = !(this.hdnID.Value == "");
                                if (!commandName)
                                {
                                    this.hdnID.Value = "0";
                                }
                                TblComment prLog = new TblComment();
                                prLog.NewsID = new int?(Convert.ToInt32(lbl.Text));
                                prLog.Comments = txt.Text;
                                prLog.RFDate = new DateTime?(DateTime.Now);
                                prLog.UserID = new int?(Convert.ToInt32(this.Request.Cookies["User"]["UserID"]));
                                commandName = !(this.hdnID.Value == "0");
                                if (commandName)
                                {
                                    TblComment.update(Convert.ToInt32(this.hdnID.Value), prLog.Comments, Convert.ToInt32(prLog.NewsID));
                                    this.hdnID.Value = "0";
                                }
                                else
                                {
                                    this.hdnID.Value = "0";
                                    prLog.Save();
                                }
                                ts.Complete();
                                txt.Text = string.Empty;
                                ((HtmlGenericControl)item.FindControl("CommemtDIV")).Visible = true;
                                gridComment.DataSourceID = "objDSExport";
                                this.objDSExport.SelectParameters["NewsID"].DefaultValue = lbl.Text;
                                ((LinkButton)item.FindControl("LnkComment")).Visible = false;
                            }
                            catch (Exception exception)
                            {
                                ex2 = exception;
                                ts.Dispose();
                                conn.Dispose();
                            }
                        }
                        finally
                        {
                            commandName = conn == null;
                            if (!commandName)
                            {
                                ((IDisposable)conn).Dispose();
                            }
                        }
                    }
                    finally
                    {
                        commandName = ts == null;
                        if (!commandName)
                        {
                            ((IDisposable)ts).Dispose();
                        }
                    }
                }
            }
            else
            {
                enumerator = this.radGrid.Items.GetEnumerator();
                try
                {
                    while (true)
                    {
                        commandName = enumerator.MoveNext();
                        if (!commandName)
                        {
                            break;
                        }
                        radItem = (GridDataItem)enumerator.Current;
                        ((LinkButton)radItem.FindControl("lnkReadMore")).Visible = true;
                        ((HtmlGenericControl)radItem.FindControl("ReadMoreDiv")).Visible = false;
                        ((Label)radItem.FindControl("lblNewsSummary")).Visible = true;
                    }
                }
                finally
                {
                    disposable = enumerator as IDisposable;
                    commandName = disposable == null;
                    if (!commandName)
                    {
                        disposable.Dispose();
                    }
                }
                this.SummaryDIVTOP.Visible = false;
                ((HtmlGenericControl)item.FindControl("ReadMoreDiv")).Visible = true;
                RadGrid radGridReadMore = (RadGrid)item.FindControl("radGridReadMore");
                ((Label)item.FindControl("lblNewsSummary")).Visible = false;
                ((LinkButton)item.FindControl("lnkReadMore")).Visible = false;
                this.sqlDSReadMore.SelectParameters["ID"].DefaultValue = e.CommandArgument.ToString();
                radGridReadMore.DataSourceID = "sqlDSReadMore";
            }
            commandName = !(e.CommandName == "Calificación");
            if (!commandName)
            {
                enumerator = this.radGrid.Items.GetEnumerator();
                try
                {
                    while (true)
                    {
                        commandName = enumerator.MoveNext();
                        if (!commandName)
                        {
                            break;
                        }
                        radItem = (GridDataItem)enumerator.Current;
                        ((HtmlGenericControl)radItem.FindControl("divCalificación")).Visible = false;
                        ((Label)radItem.FindControl("lblCalification")).Visible = true;
                    }
                }
                finally
                {
                    disposable = enumerator as IDisposable;
                    commandName = disposable == null;
                    if (!commandName)
                    {
                        disposable.Dispose();
                    }
                }
                ((HtmlGenericControl)item.FindControl("divCalificación")).Visible = true;
                ((Label)item.FindControl("lblCalification")).Visible = false;
            }
            commandName = !(e.CommandName == "Importancia");
            if (!commandName)
            {
                enumerator = this.radGrid.Items.GetEnumerator();
                try
                {
                    while (true)
                    {
                        commandName = enumerator.MoveNext();
                        if (!commandName)
                        {
                            break;
                        }
                        radItem = (GridDataItem)enumerator.Current;
                        ((HtmlGenericControl)radItem.FindControl("divImportancia")).Visible = false;
                        ((Label)radItem.FindControl("lblImportancia")).Visible = true;
                    }
                }
                finally
                {
                    disposable = enumerator as IDisposable;
                    commandName = disposable == null;
                    if (!commandName)
                    {
                        disposable.Dispose();
                    }
                }
                ((HtmlGenericControl)item.FindControl("divImportancia")).Visible = true;
                ((Label)item.FindControl("lblImportancia")).Visible = false;
            }
            commandName = !(e.CommandName == "SaveCalificación");
            if (!commandName)
            {
                ID = ((Label)item.FindControl("lblNews")).Text;
                string Calificación = ((DropDownList)item.FindControl("ddlCalificación")).SelectedItem.Text;
                try
                {
                    TblComment.updateNewsCalificación(Convert.ToInt32(ID), Calificación, "");
                    ((HtmlGenericControl)item.FindControl("divCalificación")).Visible = false;
                    ((Label)item.FindControl("lblCalification")).Visible = true;
                    ((Label)item.FindControl("lblCalification")).Text = ((DropDownList)item.FindControl("ddlCalificación")).SelectedItem.Text;
                }
                catch (Exception exception1)
                {
                    ex2 = exception1;
                }
            }
            commandName = !(e.CommandName == "SaveImportancia");
            if (commandName)
            {
                commandName = !(e.CommandName == "BrandCount");
                if (!commandName)
                {
                    ReportFuncs rpt = new ReportFuncs();
                    DataTable dt = rpt.GetReportBrandPeople(Convert.ToInt32(e.CommandArgument.ToString()));
                    this.lstBrandsAndPeople.DataSource = dt;
                    this.lstBrandsAndPeople.DataBind();
                    this.ModalPopupExtenderAddSubquestion.Show();
                }
            }
            else
            {
                ID = ((Label)item.FindControl("lblNews")).Text;
                string Importancia = ((DropDownList)item.FindControl("ddlImportancia")).SelectedItem.Text;
                try
                {
                    TblComment.updateNewsCalificación(Convert.ToInt32(ID), "", Importancia);
                    ((HtmlGenericControl)item.FindControl("divImportancia")).Visible = false;
                    ((Label)item.FindControl("lblImportancia")).Visible = true;
                    ((Label)item.FindControl("lblImportancia")).Text = ((DropDownList)item.FindControl("ddlImportancia")).SelectedItem.Text;
                }
                catch (Exception exception2)
                {
                    ex2 = exception2;
                }
            }
        }

        protected void radGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = this.ViewState["mediaTypeName"].ToString();
            this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
            this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
            this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
            this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
            this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
            this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
            this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
            this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
            this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
            this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
            this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
            this.objDS.SelectParameters["UserID"].DefaultValue = this.Request.Cookies["User"]["UserID"].ToString();
            this.objDS.SelectParameters["Importancia"].DefaultValue = this.ViewState["Importancia"].ToString();
            DataView dvSummary = new DataView();
            dvSummary = (DataView)this.objDS.Select();
            DataTable dtSummary = new DataTable();
            dtSummary = dvSummary.ToTable();
            this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
        }

        protected void radGridAll_ItemCommand(object source, GridCommandEventArgs e)
        {
            DataView dvSummary;
            DataTable dtSummary;
            bool commandName = !(e.CommandName == "GetDetail");
            if (commandName)
            {
                commandName = !(e.CommandName == "TV");
                if (commandName)
                {
                    commandName = !(e.CommandName == "Radio");
                    if (commandName)
                    {
                        commandName = !(e.CommandName == "Press");
                        if (commandName)
                        {
                            commandName = !(e.CommandName == "Internet");
                            if (!commandName)
                            {
                                this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Internet";
                                this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                                this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                                this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                                this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                                this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                                this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                                this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                                this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                                this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                                this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                                this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                                this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                                this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                                this.radGrid.DataSourceID = "objDS";
                                this.SummaryDIVTOP.Visible = true;
                                this.radGridAll.Visible = false;
                                this.ChartAvenueReport.Visible = false;
                                this.SummaryDIVTOP.Visible = false;
                                this.InnerDIV.Style.Add("display", "block");
                                this.InnerDIV.Visible = true;
                                this.InnerDIVTOP.Visible = true;
                                dvSummary = new DataView();
                                dvSummary = (DataView)this.objDSAll.Select();
                                dtSummary = new DataTable();
                                dtSummary = dvSummary.ToTable();
                                this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                                this.BindChartResult("Internet", this.ViewState["Calification"].ToString());
                            }
                        }
                        else
                        {
                            this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Press";
                            this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                            this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                            this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                            this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                            this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                            this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                            this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                            this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                            this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                            this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                            this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                            this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                            this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                            this.radGrid.DataSourceID = "objDS";
                            this.SummaryDIVTOP.Visible = true;
                            this.radGridAll.Visible = false;
                            this.ChartAvenueReport.Visible = false;
                            this.SummaryDIVTOP.Visible = false;
                            this.InnerDIV.Style.Add("display", "block");
                            this.InnerDIV.Visible = true;
                            this.InnerDIVTOP.Visible = true;
                            dvSummary = new DataView();
                            dvSummary = (DataView)this.objDSAll.Select();
                            dtSummary = new DataTable();
                            dtSummary = dvSummary.ToTable();
                            this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                            this.BindChartResult("Press", this.ViewState["Calification"].ToString());
                        }
                    }
                    else
                    {
                        this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "Radio";
                        this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                        this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                        this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                        this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                        this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                        this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                        this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                        this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                        this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                        this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                        this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                        this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                        this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                        this.radGrid.DataSourceID = "objDS";
                        this.SummaryDIVTOP.Visible = true;
                        this.radGridAll.Visible = false;
                        this.ChartAvenueReport.Visible = false;
                        this.SummaryDIVTOP.Visible = false;
                        this.InnerDIV.Style.Add("display", "block");
                        this.InnerDIV.Visible = true;
                        this.InnerDIVTOP.Visible = true;
                        dvSummary = new DataView();
                        dvSummary = (DataView)this.objDSAll.Select();
                        dtSummary = new DataTable();
                        dtSummary = dvSummary.ToTable();
                        this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                        this.BindChartResult("Radio", this.ViewState["Calification"].ToString());
                    }
                }
                else
                {
                    this.objDS.SelectParameters["mediaTypeName1"].DefaultValue = "TV";
                    this.objDS.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
                    this.objDS.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
                    this.objDS.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
                    this.objDS.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
                    this.objDS.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
                    this.objDS.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
                    this.objDS.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
                    this.objDS.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
                    this.objDS.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
                    this.objDS.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
                    this.objDS.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
                    this.objDS.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
                    this.objDS.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
                    this.radGrid.DataSourceID = "objDS";
                    this.SummaryDIVTOP.Visible = true;
                    this.radGridAll.Visible = false;
                    this.ChartAvenueReport.Visible = false;
                    this.SummaryDIVTOP.Visible = false;
                    this.InnerDIV.Style.Add("display", "block");
                    this.InnerDIV.Visible = true;
                    this.InnerDIVTOP.Visible = true;
                    dvSummary = new DataView();
                    dvSummary = (DataView)this.objDSAll.Select();
                    dtSummary = new DataTable();
                    dtSummary = dvSummary.ToTable();
                    this.ViewState["dvSummaryNewsAlertDetail"] = dtSummary;
                    this.BindChartResult("TV", this.ViewState["Calification"].ToString());
                }
            }
            else
            {
                this.Inngrid();
                this.radGrid.DataSourceID = "objDS";
                this.radGridAll.Visible = false;
                this.ChartAvenueReport.Visible = false;
                this.SummaryDIVTOP.Visible = false;
                this.InnerDIV.Style.Add("display", "block");
                this.InnerDIV.Visible = true;
                this.InnerDIVTOP.Visible = true;
                this.BindChartResult(this.ViewState["mediaTypeName"].ToString(), this.ViewState["Calification"].ToString());
            }
        }

        protected void radGridAll_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            this.FillReport();
            this.BindChart();
            this.objDSAll.SelectParameters["mediaTypeName1"].DefaultValue = this.ViewState["mediaTypeName"].ToString();
            this.objDSAll.SelectParameters["Date1"].DefaultValue = this.ViewState["sDate"].ToString();
            this.objDSAll.SelectParameters["Date2"].DefaultValue = this.ViewState["eDate"].ToString();
            this.objDSAll.SelectParameters["AdvertiserName1"].DefaultValue = this.ViewState["AdvertiserName"].ToString();
            this.objDSAll.SelectParameters["NewsTitle1"].DefaultValue = this.ViewState["NewsTitle"].ToString();
            this.objDSAll.SelectParameters["Calification1"].DefaultValue = this.ViewState["Calification"].ToString();
            this.objDSAll.SelectParameters["TitleNews"].DefaultValue = this.ViewState["TitleNews"].ToString();
            this.objDSAll.SelectParameters["Summary"].DefaultValue = this.ViewState["Summary"].ToString();
            this.objDSAll.SelectParameters["Text"].DefaultValue = this.ViewState["Text"].ToString();
            this.objDSAll.SelectParameters["mediaCode"].DefaultValue = this.ViewState["mediaCode"].ToString();
            this.objDSAll.SelectParameters["days"].DefaultValue = this.ViewState["days"].ToString();
            this.objDSAll.SelectParameters["UserID"].DefaultValue = Request.Cookies["User"]["UserID"].ToString();
            this.objDSAll.SelectParameters["AdvertiserMake"].DefaultValue = this.ViewState["AdvertiserMake"].ToString();
            this.objDSAll.SelectParameters["Importancia"].DefaultValue = ViewState["Importancia"].ToString();
            this.radGridAll.DataSourceID = "objDSAll";
            this.SummaryDIVTOP.Visible = true;
            DataView dvSummaryCount = new DataView();
            dvSummaryCount = (DataView)this.objDSAll.Select();
            DataTable dtCount = new DataTable();
            dtCount = dvSummaryCount.ToTable();
            this.ViewState["dvSummaryNewsAlertCount"] = dtCount;
        }

        protected void radGridComment_ItemCommand(object source, GridCommandEventArgs e)
        {
            string lbl;
            GridDataItem item = (GridDataItem)e.Item;
            bool commandName = !(e.CommandName == "Edit");
            if (commandName)
            {
                commandName = !(e.CommandName == "Delete");
                if (!commandName)
                {
                    lbl = ((Label)item.FindControl("lblID")).Text;
                    try
                    {
                        ActiveRecord<TblComment>.Delete(lbl);
                    }
                    catch
                    {
                        AjaxFuncs.MsgBox(this, "Failed to delete this record, because related data (child records) exists in other tables");
                    }
                }
            }
            else
            {
                lbl = ((Label)item.FindControl("lblComments")).Text;
                string lblID = ((Label)item.FindControl("lblID")).Text;
                this.hdnID.Value = lblID;
            }
        }
    }
}